package cn.hehuoren.quartz;


import org.quartz.spi.TriggerFiredBundle;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * 
 * @Title 
 * @Description 自动注入工厂类
 * @Copyright Copyright (c) 2015</p>
 * @Company 源本信息科技有限公司 Co., Ltd.</p>
 * @author ZhouMin
 * @version 1.0
 * @修改记录
 * @修改序号，修改日期，修改人，修改内容
 */
public class SpringBeanJobFactory extends org.springframework.scheduling.quartz.SpringBeanJobFactory implements
		ApplicationContextAware {
	private ApplicationContext applicationContext;

	@Override
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		this.applicationContext = applicationContext;
	}

	@Override
	protected Object createJobInstance(TriggerFiredBundle bundle)
			throws Exception {
		Object obj = super.createJobInstance(bundle);
		AutowireCapableBeanFactory beanfactory = applicationContext.getAutowireCapableBeanFactory();
		if (obj != null) {
			beanfactory.autowireBean(obj);
		}
		return obj;
	}
}
